
var _AgentInfo = {
    //是否手机访问
    isMobileVisit: false,
    //设备类型(电脑端 或 手机端)
    deviceType: "",
    //系统名称
    //电脑端范畴(Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows 2000, Mac/iOS, UNIX, Linux)
    //手机端范畴(Android, iPhone, SymbianOS, Windows Phone, iPad, iPod)
    oSSystem: "",
    //用户代理
    userAgent: navigator.userAgent,
    //平台以及版本信息
    appName: navigator.appName,
    //浏览器名称
    browserName: "",
    //浏览器版本
    browserVer: "",
    //初始化
    _init: function () {
        _AgentInfo.setDeviceAndOS();
        _AgentInfo.setBrowser();
        _AgentInfo.setMobile();
    },
    setDeviceAndOS: function () {
        var name = "";
        if (window.navigator.userAgent.indexOf("Android") != -1) {
            name = "Android";
        } else if (window.navigator.userAgent.indexOf("iPhone") != -1) {
            name = "iPhone";
        } else if (window.navigator.userAgent.indexOf("SymbianOS") != -1) {
            name = "SymbianOS";
        } else if (window.navigator.userAgent.indexOf("Windows Phone") != -1) {
            name = "Windows Phone";
        } else if (window.navigator.userAgent.indexOf("iPad") != -1) {
            name = "iPad";
        } else if (window.navigator.userAgent.indexOf("iPod") != -1) {
            name = "iPod";
        }
        if (name != "") {
            _AgentInfo.oSSystem = name;
            _AgentInfo.deviceType = "Mobile";
            return;
        }
        if (window.navigator.userAgent.indexOf("Windows NT 10.0") != -1) {
            name = "Windows 10";
        } else if (window.navigator.userAgent.indexOf("Windows NT 6.2") != -1) {
            name = "Windows 8";
        } else if (window.navigator.userAgent.indexOf("Windows NT 6.1") != -1) {
            name = "Windows 7";
        } else if (window.navigator.userAgent.indexOf("Windows NT 6.0") != -1) {
            name = "Windows Vista";
        } else if (window.navigator.userAgent.indexOf("Windows NT 5.1") != -1) {
            name = "Windows XP";
        } else if (window.navigator.userAgent.indexOf("Windows NT 5.0") != -1) {
            name = "Windows 2000";
        } else if (window.navigator.userAgent.indexOf("Mac") != -1) {
            name = "Mac/iOS";
        } else if (window.navigator.userAgent.indexOf("X11") != -1) {
            name = "UNIX";
        } else if (window.navigator.userAgent.indexOf("Linux") != -1) {
            name = "Linux";
        }
        _AgentInfo.oSSystem = name;
        _AgentInfo.deviceType = "Computer";
    },
    setBrowser: function () {
        var nAgt = navigator.userAgent;
        var browserName = navigator.appName;
        var fullVersion = '' + parseFloat(navigator.appVersion);
        var majorVersion = parseInt(navigator.appVersion, 10);
        var nameOffset, verOffset, ix;

        //Opera浏览器(In Opera, the true version is after "Opera" or after "Version")
        if ((verOffset = nAgt.indexOf("Opera")) != -1) {
            browserName = "Opera";
            fullVersion = nAgt.substring(verOffset + 6);
            if ((verOffset = nAgt.indexOf("Version")) != -1)
                fullVersion = nAgt.substring(verOffset + 8);
        }
        //IE浏览器(( ver >= ie7) In MSIE, the true version is after "MSIE" in userAgent)
        else if ((nAgt.indexOf("Trident")) != -1) {
            if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
                fullVersion = nAgt.substring(verOffset + 5);
            } else {
                fullVersion = '11.0';
            }
            if (fullVersion == 5) {
                fullVersion = "11.0";
            }
                browserName = "IE";
        }
        //谷歌浏览器(In Chrome, the true version is after "Chrome")
        else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
            browserName = "Chrome";
            fullVersion = nAgt.substring(verOffset + 7);
        }
        //Safari浏览器(In Safari, the true version is after "Safari" or after "Version")
        else if ((verOffset = nAgt.indexOf("Safari")) != -1) {
            browserName = "Safari";
            fullVersion = nAgt.substring(verOffset + 7);
            if ((verOffset = nAgt.indexOf("Version")) != -1)
                fullVersion = nAgt.substring(verOffset + 8);
        }
        //Firefox浏览器(In Firefox, the true version is after "Firefox")
        else if ((verOffset = nAgt.indexOf("Firefox")) != -1) {
            browserName = "Firefox";
            fullVersion = nAgt.substring(verOffset + 8);
        }
        //非PC浏览器( In most other browsers, "name/version" is at the end of userAgent)
        else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
            browserName = nAgt.substring(nameOffset, verOffset);
            fullVersion = nAgt.substring(verOffset + 1);
            if (browserName.toLowerCase() == browserName.toUpperCase()) {
                browserName = navigator.appName;
            }
        }
        // trim the fullVersion string at semicolon/space if present
        if ((ix = fullVersion.indexOf(";")) != -1)
            fullVersion = fullVersion.substring(0, ix);
        if ((ix = fullVersion.indexOf(" ")) != -1)
            fullVersion = fullVersion.substring(0, ix);
            majorVersion = parseInt('' + fullVersion, 10);
        if (isNaN(majorVersion)) {
            fullVersion = '' + parseFloat(navigator.appVersion);
            majorVersion = parseInt(navigator.appVersion, 10);
        }
        _AgentInfo.browserName = browserName;
        _AgentInfo.browserVer = fullVersion;
    },
    //是否手机访问
    setMobile: function () {
        if (_AgentInfo.deviceType == "mobile") {
            _AgentInfo.isMobileVisit = true;
            return true;
        }
            _AgentInfo.isMobileVisit = false;
            return false;
    }
}

_AgentInfo._init();


